package com.itheima.service.db.soul;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.itheima.mapper.soul.OptionsMapper;
import com.itheima.soul.Options;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class OptinsServiceImpl implements OptinsService {

    @Autowired
    OptionsMapper optionsMapper;


    @Override
    public List<Options> findByTitleId(Long titleId) {


        // QueryWrapper<Options> wrapper = new QueryWrapper<>();
        // wrapper.eq("title_id",titleId);
        //
        // List<Options> options = optionsMapper.selectList(wrapper);

        return optionsMapper.findByTitleId(titleId);
    }

    @Override
    public void save(Options options) {
        optionsMapper.insert(options);
    }

    @Override
    public void update(Options options) {

        QueryWrapper<Options> wrapper = new QueryWrapper<>();
        wrapper.eq("id",options.getId());


        optionsMapper.update(options,wrapper);
    }

    @Override
    public void delete(Long titleId) {
        QueryWrapper<Options> wrapper = new QueryWrapper<>();

        wrapper.eq("title_id",titleId);
        optionsMapper.delete(wrapper);

    }
}
